﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Brainee.Search;

namespace Brainee.Optimization
{
  public class SteepestAscentStrategy : IOptimizationStrategy
  {
    public OptimizationState SelectNeighbor (OptimizationState current, IOptimizationProblem problem)
    {
      IState neighbor = null;
      double maxValue = double.MinValue;

      foreach (IState state in problem.Successors (current.State))
      {
        double value = problem.Evaluate (state);
        if (value > maxValue)
        {
          neighbor = state;
          maxValue = value;
        }
      }

      return new OptimizationState (neighbor, maxValue);
    }
  }
}
